package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SuccessBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.SetGoodsOrderCommentModel;

public class CommentGoodsActivity extends BaseActivity implements View.OnClickListener {

    ImageView commentgoods_fh;
    EditText commentgoods_content;
    Button commentgoods_btn;
    String order_id;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_comment_goods);
        commentgoods_fh = (ImageView)findViewById(R.id.commentgoods_fh);
        commentgoods_content = (EditText)findViewById(R.id.commentgoods_content);
        commentgoods_btn = (Button)findViewById(R.id.commentgoods_btn);
        order_id = getIntent().getStringExtra("order_id");
    }

    @Override
    void initEvent() {
        commentgoods_fh.setOnClickListener(this);
        commentgoods_btn.setOnClickListener(this);
    }

    @Override
    void initDate() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.commentgoods_fh:
                finish();
                break;
            case R.id.commentgoods_btn:
                String content = commentgoods_content.getText().toString().trim();
                if (content.equals("")){
                    Toast.makeText(CommentGoodsActivity.this,"评论信息不能为空",Toast.LENGTH_SHORT).show();
                }
                else{
                    SetGoodsOrderCommentModel setGoodsOrderCommentModel = new SetGoodsOrderCommentModel();
                    setGoodsOrderCommentModel.setGoodsOrderComment(order_id, content, new TListener<SuccessBean>() {
                        @Override
                        public void onResponse(SuccessBean successBean) {
                            if (successBean.getSuccess().equals("1")){
                                Toast.makeText(CommentGoodsActivity.this,"评论成功",Toast.LENGTH_SHORT).show();
                                finish();
                            }
                            else{
                                Toast.makeText(CommentGoodsActivity.this,"评论失败",Toast.LENGTH_SHORT).show();
                            }
                        }

                        @Override
                        public void onFail(String msg) {

                        }
                    });
                }
                break;
        }
    }
}
